Home |
| Latest | About | Random
## Answers to the DNA analysis problem. ```cpp #include #include using namespace std; int main(){ const string dna = "AATCGCCACCGGAAGCAAGAGGGAGCTGGTCTGGATATCGTGATCCTTTGGGTAAAGATTGGAGTTAACACCTTCGGTGTCCAGCAATGCTAATACGGTTGGGAAACATATAGGACTCGCGGCAGCTGGTGGATCGTGACAAATAAAGGGAAATCCCGTTCTCGGGTCAAGTAGTTCTCTCATGAACCAAGCCGACCTCAGAGGTACGGATGTAAAGGTTACCAGGGCTATCGGAACTAGATCGGTACAGGACGTGGACAGTATGCAACCATAATGCGTCATTAATGGGTTTATGAGCCT"; cout << "First section of this dna: " << dna.substr(0, 5) << endl; cout << "Sixth section of this dna: " << dna.substr((6-1) * 5, 5) << endl; cout << "\n\n\n"; const string cancerous = "GGGAAA"; const size_t occ_1 = dna.find(cancerous); cout << "First 4 letters after cancerous sequence " + cancerous + " is: " << dna.substr(occ_1 + cancerous.length(), 4) << endl; cout << "\n\n\n"; const size_t occ_2 = dna.find(cancerous, occ_1 + 1); cout << "Is there a second occurrence of " + cancerous + "? " << boolalpha << (occ_2 != string::npos); // Careful: if occ_2 were string::npos, then occ_2 + 1 wraps around to 0 // and we would search from the beginning again! Here occ_2 is found. cout << "\n\n\n"; const size_t occ_3 = dna.find(cancerous, occ_2 + 1); cout << "Is there a third occurrence of " + cancerous + "? " << boolalpha << (occ_3 != string::npos); cout << "\n\n\n"; const string to_remove = "CAAATAAA"; const size_t pos_1 = dna.find(to_remove); const string head = dna.substr(0, pos_1); const string tail = dna.substr(pos_1 + to_remove.length()); cout << "After removing " + to_remove + ", we get: \n" << head + tail << endl; cout << "\n\n\n"; const string starting = "GGGAAA"; const string ending = "CATAA"; const size_t start_pos = dna.find(starting); const size_t end_pos = dna.rfind(ending); cout << "The sub-DNA strictly between the first " + starting + " and " + ending + " is: \n"; cout << dna.substr(start_pos + starting.length(), end_pos - start_pos - starting.length() ); // extracting two doubles here cout << "\n\n\n"; const string data = "temp=96F;hum=53%"; const string t_text = "temp="; const string h_text = "hum="; double temp = stod(data.substr(data.find(t_text) + t_text.length())); double hum = stod(data.substr(data.find(h_text) + h_text.length())); cout << "The sum is of the two doubles in the string " + data + " is: " << temp + hum; return 0; } ```